/*
 *    Copyright (c) 2018-2025, boss All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * Redistributions of source code must retain the above copyright notice,
 * this list of conditions and the following disclaimer.
 * Redistributions in binary form must reproduce the above copyright
 * notice, this list of conditions and the following disclaimer in the
 * documentation and/or other materials provided with the distribution.
 * Neither the name of the boss developer nor the names of its
 * contributors may be used to endorse or promote products derived from
 * this software without specific prior written permission.
 * Author: boss
 */
package com.hopes.bizz.risk.hid.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hopes.bizz.common.core.constant.CommonConstant;
import com.hopes.bizz.risk.common.constant.HidDicConstant;
import com.hopes.bizz.risk.common.constant.enums.RiskHidSourceEnum;
import com.hopes.bizz.risk.hid.dto.RiskHidHiddenDangerDTO;
import com.hopes.bizz.risk.hid.entity.RiskHidCheckListConfigEntity;
import com.hopes.bizz.risk.hid.entity.RiskHidCheckTaskRecordEntity;
import com.hopes.bizz.risk.hid.mapper.RiskHidCheckTaskRecordMapper;
import com.hopes.bizz.risk.hid.service.RiskHidCheckListConfigService;
import com.hopes.bizz.risk.hid.service.RiskHidCheckTaskRecordService;
import com.hopes.bizz.risk.hid.service.RiskHidHiddenDangerService;
import com.hopes.bizz.risk.hid.vo.RiskHidCheckTaskHidVO;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;

/**
 * 隐患检查记录
 *
 * @author daijie
 * @date 2023-07-28 15:20:59
 */
@Service
@RequiredArgsConstructor
public class RiskHidCheckTaskRecordServiceImpl extends ServiceImpl<RiskHidCheckTaskRecordMapper, RiskHidCheckTaskRecordEntity> implements RiskHidCheckTaskRecordService {

    private final RiskHidHiddenDangerService riskHidHiddenDangerService;
    private final RiskHidCheckListConfigService riskHidCheckListConfigService;

    @Override
    public List<RiskHidCheckTaskRecordEntity> listByTaskId(Long taskId) {
        LambdaQueryWrapper<RiskHidCheckTaskRecordEntity> wrapper = Wrappers.lambdaQuery();
        wrapper.eq(RiskHidCheckTaskRecordEntity::getTaskId, taskId);
        return this.list(wrapper);
    }

    @Override
    public List<RiskHidCheckTaskRecordEntity> listExByTaskId(Long taskId) {
        LambdaQueryWrapper<RiskHidCheckTaskRecordEntity> wrapper = Wrappers.lambdaQuery();
        wrapper.eq(RiskHidCheckTaskRecordEntity::getTaskId, taskId);
        wrapper.eq(RiskHidCheckTaskRecordEntity::getConclusion, HidDicConstant.RISK_HID_CHECKLIST_TASK_CONCLUSION_EXCEPTION);
        return this.list(wrapper);
    }

    @Override
    public Integer getCheckType(Long id) {
        RiskHidCheckTaskRecordEntity record = this.getById(id);
        RiskHidCheckListConfigEntity riskHidCheckListConfig = riskHidCheckListConfigService.getById(record.getRiskHidCheckListConfigId());
        return riskHidCheckListConfig.getCheckType();
    }

    @Override
    public RiskHidCheckTaskHidVO initHidInfo(Long id) {
        RiskHidCheckTaskHidVO res = new RiskHidCheckTaskHidVO();
        RiskHidCheckTaskRecordEntity record = this.getById(id);
        RiskHidCheckListConfigEntity config = riskHidCheckListConfigService.getById(record.getRiskHidCheckListConfigId());
        res.setHidSource(config.getCheckType());
        res.setHidName(config.getCheckName() + "-" + record.getItem());
        res.setHidContent(record.getCheckDesc());
        res.setHidLevel(HidDicConstant.DANGER_LEVEL_GENERAL);
        res.setReportDate(new Date());
        res.setReportPhoto(record.getPhone());
        return res;
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean saveTaskHidden(RiskHidHiddenDangerDTO riskHidHiddenDangerDTO) {
        return false;
    }
}
